<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>万息金融-后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/admin/css/font.css">
    <link rel="stylesheet" href="/admin/css/xadmin.css">
    <script src="/admin/js/jquery.min.js"></script>
    <script src="/admin/js/myAjax.js"></script>
    <script src="/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/admin/js/xadmin.js"></script>
    <script src="/admin/js/wxlayedit.js"></script>
    <script src="/admin/js/intercept.js"></script>
    <script src="/admin/js/common.js"></script>


</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <select id="businessCategory" name="businessCategory.id">
                                <option disabled selected style='display: none;'></option>
                            </select>
                        </div>


                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name" placeholder="名称" autocomplete="off"
                                   class="layui-input"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table" id="test" lay-data="{toolbar: '#toolbarDemo',id:'test'}"
                           lay-filter="bcfilt">
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>
</div>
</body>
<script>
    $(
        function setNewsCate(){
            let res=myAjax(ipAddress()+"/business/category/g",{},"get");
            let html="";
            for(let i=0;i<res.data.length;i++){
                html+='<option value="'+res.data[i].id+'">'+res.data[i].name+'</option>'
            }
            $('#businessCategory').append(html);
        })
</script>


<script type="text/html" id="businessLogo">
    <img style="max-width: 50px" src="{{d.pic}}">
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="update">编辑</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"> 新增</button>
    </div>
</script>
<script>
    layui.use(['laydate', 'form', 'jquery', 'table', 'laypage'], function () {
        var laydate = layui.laydate
            , $ = layui.jquery
            , form = layui.form
            , layPage = layui.laypage
            , table = layui.table;


        // 条件搜索
        form.on('submit(sreach)',
            function (data) {
                //执行渲染
                table.render({
                    elem: '#test'
                    , page: true
                    , url: ipAddress()+"/business/g"
                    , text: '没有数据'
                    , where: data.field
                    , toolbar: '#toolbarDemo'
                    , cols: [[
                        {field: 'name', width: 120, sort: true, title: '名称'}
                        , {field: 'pic', minWidth: 150, templet: '#businessLogo', title: '业务图片'}
                        , {field: 'content', minWidth: 80, title: '内容介绍'}
                        , {
                            field: 'businessCategory', minWidth: 80, title: '所属类别', templet: function (d) {
                                return d.businessCategory.name;
                            }
                        }
                        , {field: 'orginPrice', sort: true, minWidth: 80, title: '原价'}
                        , {field: 'price', sort: true, minWidth: 80, title: '现价'}
                        , {field: 'createTime', minWidth: 100, title: '创建时间'}
                        , {field: 'updateTime', sort: true, title: '修改时间'}
                        , {field: 'remark', title: '批注'}
                        , {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo', title: '操作'}
                    ]]
                });
                return false;
            })
        // 方法渲染首次点击页面
        table.render({
            elem: '#test'
            , page: true
            , url: ipAddress()+"/business/g"
            , method: 'get'
            , text: '没有数据'
            , toolbar: '#toolbarDemo'
            , cols: [[
                {field: 'name', width: 120, sort: true, title: '名称'}
                , {field: 'pic', minWidth: 150, templet: '#businessLogo', title: '业务图片'}
                , {field: 'content', minWidth: 80, title: '内容介绍'}
                , {
                    field: 'businessCategory', minWidth: 80, title: '所属类别', templet: function (d) {
                        return d.businessCategory.name;
                    }
                }
                , {field: 'orginPrice', sort: true, minWidth: 80, title: '原价'}
                , {field: 'price', sort: true, minWidth: 80, title: '现价'}
                , {field: 'createTime', minWidth: 100, title: '创建时间'}
                , {field: 'updateTime', sort: true, title: '修改时间'}
                , {field: 'remark', title: '批注'}
                , {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo', title: '操作'}
            ]]
        });
        //头部工具栏事件:  新增
        table.on('toolbar(bcfilt)', function (obj) {

            switch (obj.event) {
                case 'add':
                    layer.open({
                        title: '信息修改',
                        shade: 0.1,
                        area: ['1000px', '500px'],
                        type: 2,
                        content: './bAdd.html',
                    })
                    break;
            }
            ;
        });

        //单元格工具事件：编辑  删除
        table.on('tool(bcfilt)', function (obj) {
            var data = obj.data; //获得当前行数据 layui-laypage-count
            switch (obj.event) {
                case 'delete':
                    layer.confirm('确认要删除吗？', function (index) {
                        let indx = table.cache.test.length;
                        //发异步删除数据
                        let res = myAjax(ipAddress()+'/business/d/'+data.id, {}, "delete");
                        let pg=$(".layui-laypage-curr").children().eq(1).text();
                        if (res.count == 1) {
                            if (indx == 1) {
                                table.reload('test', {page: {curr: pg-1}})
                            } else {
                                table.reload('test', {})
                            }
                            layer.msg('已删除!', {icon: 1, time: 1000});
                        } else {
                            layer.msg('删除失败!', {icon: 1, time: 1000});
                        }
                    });

                    break;
                case 'update':
                    let res = myAjax(ipAddress()+'/business/g/'+data.id, {}, "get");
                    sessionStorage.setItem("businessId",data.id);
                    layer.open({
                        title: '信息修改',
                        shade: 0.1,
                        area: ['1000px', '500px'],
                        type: 2,
                        content: './bUpdate.html',
                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);
                            body.find('form').find('#Logo').attr("src", res.data.pic);
                            body.find('form').find('#name').val(res.data.name);
                            body.find('form').find('#id').val(data.id);
                            body.find('form').find('#layeditDemo').text(res.data.content);
                            body.find('form').find('#remark').val(res.data.remark);
                            body.find('form').find('#orginPrice').val(res.data.orginPrice);
                            body.find('form').find('#price').val(res.data.price);
                        }
                    })
                    break;
            }
            ;
        });
    })
    ;

</script>
</html>